import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/home.vue'
import Nav from '../views/home/nav.vue'
import Category from '../views/home/category.vue'
import Goodlist from '@/views/goods/goodlist.vue'
import Goodsdesc from '@/views/goods/goodsdesc.vue'
import Login from '@/views/login/login.vue'
import Formlogin from '@/views/login/formlogin.vue'
import Smslogin from '@/views/login/smslogin.vue'
import Register from '@/views/login/register.vue'
import Useredit from '@/views/users/useredit.vue'
import Orderlist from '@/views/order/orderlist.vue'
import Addresslist from '@/views/ress/addresslist.vue'
import Orderconfirm from '@/views/order/orderconfirm.vue'
import Addressadd from '@/views/ress/addressadd.vue'
import Pay from '@/views/order/pay.vue'
Vue.use(VueRouter)

const routes = [
  // 主布局路由
  {
    path: '/',
    name: 'layout',
    component: () => import('@/layouts/MainLayout.vue'),
    children: [
      {
        path: '',
        name: 'home',
        component: () => import('@/views/home/Home.vue'),
        meta: { title: '首页' }
      },
      {
        path: '/category',
        name: 'category',
        component: Category
      },
      // 需要登录的路由组
  {
    path: '',
    component: () => import('@/layouts/AuthLayout.vue'),
    meta: { requiresAuth: true },
    children: [
      {
        path: '/cart',
        name: 'cart',
        component: () => import('@/views/cart/Cart.vue'),
        meta: { title: '购物车' }
      },
      {
        path: '/order',
        name: 'order',
        component: () => import('@/views/order/Order.vue'),
        meta: { title: '我的订单' }
      }
    ]
  },
      {
        path: '/user',
        name: 'user',
        component: () => import('../views/home/user.vue')
      }
    ]
  },
  // 商品模块路由
  {
    path: '/goods',
    name: 'goods',
    component: () => import('@/layouts/GoodsLayout.vue'),
    children: [
      {
        path: 'list',
        name: 'goods.list',
        component: () => import('@/views/goods/Goodlist.vue'),
        meta: { title: '商品列表' }
      },
      {
        path: 'desc/:id',
        name: 'goods.desc',
        component: () => import('@/views/goods/Goodsdesc.vue'),
        meta: { title: '商品详情', requiresAuth: true },
        props: true
      }
    ]
  },
  {
    path: '/goodsdesc',
    name: 'goodsdesc',
    component: Goodsdesc
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/formlogin',
    name: 'formlogin',
    component: Formlogin
  },
  {
    path: '/smslogin',
    name: 'smslogin',
    component: Smslogin
  },
  {
    path: '/register',
    name: 'register',
    component: Register
  },
  {
    path: '/useredit',
    name: 'useredit',
    component: Useredit
  },
  {
    path: '/orderlist',
    name: 'orderlist',
    component: Orderlist
  },
  {
    path: '/addresslist',
    name: 'addresslist',
    component: Addresslist
  },
  {
    path: '/orderconfirm',
    name: 'orderconfirm',
    component: Orderconfirm
  },
  {
    path: '/addressadd',
    name: 'addressadd',
    component: Addressadd
  },
  {
    path: '/pay',
    name: 'pay',
    component: Pay
  }
]

const router = new VueRouter({
  routes
})

export default router
